package db

import (
	"fmt"
	config2 "gin-cli/utils/config"
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/mysql"
)

func Mysql () *gorm.DB {
	host := config2.Get("database.mysql.host")
	port := config2.Get("database.mysql.port")
	username := config2.Get("database.mysql.username")
	password := config2.Get("database.mysql.password")
	db_name := config2.Get("database.mysql.db_name")

	conn := fmt.Sprintf("%s:%s@(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", username, password, host, port, db_name)

	db, err := gorm.Open("mysql", conn)
	if err!= nil{
		panic(err)
	}
	//defer db.Close()
	db.SingularTable(true)
	return db
}
